package com.leetcode.algorithm.y22.m06;

/**
 * 189. 轮转数组
 * 
 * https://leetcode.cn/problems/rotate-array/
 * 
 * @author jie.deng
 *
 */
class Question0189Solution01 {
	
	public void rotate(int[] nums, int k) {
		int len = nums.length;
		k = k % len;
		int[] tmp = new int[k];
		int i = len - k;
		for (int idx = 0; idx < k; idx++) {
			tmp[idx] = nums[i + idx];
		}

		for (int idx = len - k - 1; idx >= 0; idx--) {
			nums[idx + k] = nums[idx];
		}

		for (int idx = 0; idx < k; idx++) {
			nums[idx] = tmp[idx];
		}
	}
    
}